<?xml version="1.0"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head><title>SASAPI</title><script src="../../../quicknav.js" type="text/javascript"></script><script><!--
document.quicknavBasePath="../../../index-files";
//--></script><link href="../../../style.css" title="JavaDoc" rel="stylesheet" type="text/css"/><link href="../../../unnatural.css" title="Unnatural" rel="alternate stylesheet" type="text/css"/><link href="../../../overview-summary.html" title="Overview" rel="top"/><meta name="generator" content="http://www.badgers-in-foil.co.uk/projects/as2api/"/></head><body><pre><span class="lineno" id="1">     1  </span><span class="comment doc">/**
<span class="lineno" id="2">     2  </span> * com.sekati.services.SOAPClient
<span class="lineno" id="3">     3  </span> * @version 1.0.6
<span class="lineno" id="4">     4  </span> * @author jason m horwitz | sekati.com
<span class="lineno" id="5">     5  </span> * Copyright (C) 2007  jason m horwitz, Sekat LLC. All Rights Reserved.
<span class="lineno" id="6">     6  </span> * Released under the MIT License: http://www.opensource.org/licenses/mit-license.php
<span class="lineno" id="7">     7  </span> */</span>
<span class="lineno" id="8">     8  </span>
<span class="lineno" id="9">     9  </span><span class="key">import</span> com.sekati.core.CoreObject;
<span class="lineno" id="10">    10  </span><span class="key">import</span> com.sekati.events.Dispatcher;
<span class="lineno" id="11">    11  </span><span class="key">import</span> com.sekati.log.Logger;
<span class="lineno" id="12">    12  </span><span class="key">import</span> com.sekati.services.ISOAPClient;
<span class="lineno" id="13">    13  </span><span class="key">import</span> com.sekati.services.SOAPEvent;
<span class="lineno" id="14">    14  </span><span class="key">import</span> com.sekati.utils.Delegate;
<span class="lineno" id="15">    15  </span><span class="key">import</span> com.sekati.validate.TypeValidation;
<span class="lineno" id="16">    16  </span><span class="key">import</span> mx.services.SOAPCall;
<span class="lineno" id="17">    17  </span><span class="key">import</span> mx.services.WebService;
<span class="lineno" id="18">    18  </span>
<span class="lineno" id="19">    19  </span><span class="comment doc">/**
<span class="lineno" id="20">    20  </span> * Soap Client class to be used with &lt;a href="http://consume.sekati.com/?sid=swsdk"&gt;JNuSOAP&lt;/a&gt;.&lt;br&gt;
<span class="lineno" id="21">    21  </span> * TODO Replace Singleton Dispatcher for call result handling granularity.
<span class="lineno" id="22">    22  </span> * 
<span class="lineno" id="23">    23  </span> * &lt;br&gt;Q: 'There are multiple possible ports in the WSDL file; please specify a service name and port name!?'
<span class="lineno" id="24">    24  </span> * &lt;br&gt;A: add port to class instance, seach for "port" in the wsdl &amp; see url's below for more info.
<span class="lineno" id="25">    25  </span> * 
<span class="lineno" id="26">    26  </span> * @see &lt;a href="http://www.intangibleinc.com/movabletype/archives/000007.html"&gt;http://www.intangibleinc.com/movabletype/archives/000007.html&lt;/a&gt;
<span class="lineno" id="27">    27  </span> * @see &lt;a href="http://livedocs.macromedia.com/fms/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00000796.html"&gt;http://livedocs.macromedia.com/fms/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;file=00000796.html&lt;/a&gt;
<span class="lineno" id="28">    28  </span> * @see &lt;a href="http://www.flash-db.com/Tutorials/lclasses/lclasses.php?page=2"&gt;http://www.flash-db.com/Tutorials/lclasses/lclasses.php?page=2&lt;/a&gt;
<span class="lineno" id="29">    29  </span> * @see &lt;a href="http://www.adobe.com/devnet/flash/articles/flmxpro_webservices_03.html"&gt;http://www.adobe.com/devnet/flash/articles/flmxpro_webservices_03.html&lt;/a&gt;
<span class="lineno" id="30">    30  </span> */</span>
<span class="lineno" id="31">    31  </span><span class="key">class</span> com.sekati.services.SOAPClient <span class="key">extends</span> CoreObject <span class="key">implements</span> ISOAPClient {
<span class="lineno" id="32">    32  </span>
<span class="lineno" id="33">    33  </span>	<span class="key">private</span> <span class="key">static</span> <span class="key">var</span> _instance:SOAPClient;
<span class="lineno" id="34">    34  </span>	<span class="key">private</span> <span class="key">var</span> _ws:WebService;
<span class="lineno" id="35">    35  </span>	<span class="key">private</span> <span class="key">var</span> _wsdl:String;
<span class="lineno" id="36">    36  </span>	<span class="key">private</span> <span class="key">var</span> _port:String;
<span class="lineno" id="37">    37  </span>	<span class="key">private</span> <span class="key">var</span> _isConnected:Boolean;
<span class="lineno" id="38">    38  </span>	<span class="key">private</span> <span class="key">var</span> _isVerbose:Boolean;
<span class="lineno" id="39">    39  </span>
<span class="lineno" id="40">    40  </span>	<span class="comment doc">/**
<span class="lineno" id="41">    41  </span>	 * Singleton Private Constructor
<span class="lineno" id="42">    42  </span>	 */</span>
<span class="lineno" id="43">    43  </span>	<span class="key">private</span> <span class="key">function</span> SOAPClient() {
<span class="lineno" id="44">    44  </span>		<span class="key">super</span>( );
<span class="lineno" id="45">    45  </span>		_isConnected = <span class="key">false</span>;
<span class="lineno" id="46">    46  </span>		_isVerbose = <span class="key">false</span>;
<span class="lineno" id="47">    47  </span>	}
<span class="lineno" id="48">    48  </span>
<span class="lineno" id="49">    49  </span>	<span class="comment doc">/**
<span class="lineno" id="50">    50  </span>	 * Singleton Accessor.
<span class="lineno" id="51">    51  </span>	 * @return SOAPClient
<span class="lineno" id="52">    52  </span>	 */</span>
<span class="lineno" id="53">    53  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> getInstance():SOAPClient {
<span class="lineno" id="54">    54  </span>		<span class="key">if</span> (!_instance) {
<span class="lineno" id="55">    55  </span>			_instance = <span class="key">new</span> SOAPClient( );
<span class="lineno" id="56">    56  </span>		}
<span class="lineno" id="57">    57  </span>		<span class="key">return</span> _instance;
<span class="lineno" id="58">    58  </span>	}
<span class="lineno" id="59">    59  </span>
<span class="lineno" id="60">    60  </span>	<span class="comment doc">/**
<span class="lineno" id="61">    61  </span>	 * shorthand singleton accessor getter.
<span class="lineno" id="62">    62  </span>	 * @return SOAPClient
<span class="lineno" id="63">    63  </span>	 */</span>
<span class="lineno" id="64">    64  </span>	<span class="key">public</span> <span class="key">static</span> <span class="key">function</span> get $():SOAPClient {
<span class="lineno" id="65">    65  </span>		<span class="key">return</span> SOAPClient.getInstance( );	
<span class="lineno" id="66">    66  </span>	}
<span class="lineno" id="67">    67  </span>
<span class="lineno" id="68">    68  </span>	<span class="comment doc">/**
<span class="lineno" id="69">    69  </span>	 * Connect the SOAP client to webservice.
<span class="lineno" id="70">    70  </span>	 * @param wsdl (String) wsdl URL.
<span class="lineno" id="71">    71  </span>	 * @param port (String) optional service port - &lt;a href="http://www.adobe.com/devnet/flash/articles/flmxpro_webservices_03.html"&gt;see more&lt;/a&gt;
<span class="lineno" id="72">    72  </span>	 * @return Void
<span class="lineno" id="73">    73  </span>	 */</span>
<span class="lineno" id="74">    74  </span>	<span class="key">public</span> <span class="key">function</span> connect(wsdl:String, port:String):Void {
<span class="lineno" id="75">    75  </span>		_wsdl = wsdl;
<span class="lineno" id="76">    76  </span>		_port = port;
<span class="lineno" id="77">    77  </span>		_ws = <span class="key">new</span> WebService( _wsdl );
<span class="lineno" id="78">    78  </span>		<span class="key">if</span> (port) _ws._portName = port;
<span class="lineno" id="79">    79  </span>		_ws.onLoad = Delegate.create( _instance, connectLoad );
<span class="lineno" id="80">    80  </span>		_ws.onFault = Delegate.create( _instance, connectFault );
<span class="lineno" id="81">    81  </span>	}
<span class="lineno" id="82">    82  </span>
<span class="lineno" id="83">    83  </span>	<span class="comment doc">/**
<span class="lineno" id="84">    84  </span>	 * SOAP webservice method call.
<span class="lineno" id="85">    85  </span>	 * @param method (String) service method name
<span class="lineno" id="86">    86  </span>	 * @param args (Array) array of service method arguments
<span class="lineno" id="87">    87  </span>	 * @return Void
<span class="lineno" id="88">    88  </span>	 */</span>
<span class="lineno" id="89">    89  </span>	<span class="key">public</span> <span class="key">function</span> call(method:String, args:Array):Void {
<span class="lineno" id="90">    90  </span>		<span class="comment">/*
<span class="lineno" id="91">    91  </span>		 * Call Remote WebService Method using args array; then broadcast the result/fault event.
<span class="lineno" id="92">    92  </span>		 * NOTE: webservice method invocations return an asynchronous callback. 
<span class="lineno" id="93">    93  </span>		 * callback is undefined if the service itself is not created (and service.onFault fires)
<span class="lineno" id="94">    94  </span>		 */</span>
<span class="lineno" id="95">    95  </span>		<span class="key">var</span> _call:Function = _ws[method].apply( _ws, args );
<span class="lineno" id="96">    96  </span>		_call.onResult = Delegate.create( _instance, callResult, method );
<span class="lineno" id="97">    97  </span>		_call.onFault = Delegate.create( _instance, callFault, method, _call.request, _call.response );
<span class="lineno" id="98">    98  </span>	}
<span class="lineno" id="99">    99  </span>
<span class="lineno" id="100">   100  </span>	<span class="comment doc">/**
<span class="lineno" id="101">   101  </span>	 * Get verbosity SOAPClient sends to {@link Logger} 
<span class="lineno" id="102">   102  </span>	 * @return Boolean
<span class="lineno" id="103">   103  </span>	 */</span>
<span class="lineno" id="104">   104  </span>	<span class="key">public</span> <span class="key">function</span> get verbose():Boolean {
<span class="lineno" id="105">   105  </span>		<span class="key">return</span> _isVerbose;	
<span class="lineno" id="106">   106  </span>	}
<span class="lineno" id="107">   107  </span>
<span class="lineno" id="108">   108  </span>	<span class="comment doc">/**
<span class="lineno" id="109">   109  </span>	 * Set verbosity SOAPClient sends to {@link Logger} 
<span class="lineno" id="110">   110  </span>	 * @param b (Boolean)
<span class="lineno" id="111">   111  </span>	 * @return Void
<span class="lineno" id="112">   112  </span>	 */</span>
<span class="lineno" id="113">   113  </span>	<span class="key">public</span> <span class="key">function</span> set verbose(b:Boolean):Void {
<span class="lineno" id="114">   114  </span>		_isVerbose = b;	
<span class="lineno" id="115">   115  </span>	}	
<span class="lineno" id="116">   116  </span>
<span class="lineno" id="117">   117  </span>	<span class="comment doc">/**
<span class="lineno" id="118">   118  </span>	 * Connect onLoad Handler
<span class="lineno" id="119">   119  </span>	 * @param wsdl (String)
<span class="lineno" id="120">   120  </span>	 * @return Void
<span class="lineno" id="121">   121  </span>	 */</span>
<span class="lineno" id="122">   122  </span>	<span class="key">private</span> <span class="key">function</span> connectLoad(wsdl:String):Void {
<span class="lineno" id="123">   123  </span>		_isConnected = <span class="key">true</span>;
<span class="lineno" id="124">   124  </span>		Dispatcher.$.dispatchEvent( <span class="key">new</span> SOAPEvent( SOAPEvent.CONNECT, {wsdl:_wsdl} ) );
<span class="lineno" id="125">   125  </span>		<span class="key">if</span> (_isVerbose) Logger.$.status( _instance.toString( ), <span class="str_const">"Webservice Connection SUCCESS Load: '"</span> + _wsdl + <span class="str_const">"'"</span> );		
<span class="lineno" id="126">   126  </span>	}
<span class="lineno" id="127">   127  </span>
<span class="lineno" id="128">   128  </span>	<span class="comment doc">/**
<span class="lineno" id="129">   129  </span>	 * Connect onFault Handler
<span class="lineno" id="130">   130  </span>	 * @param fault (Object)
<span class="lineno" id="131">   131  </span>	 * @return Void
<span class="lineno" id="132">   132  </span>	 */</span>
<span class="lineno" id="133">   133  </span>	<span class="key">private</span> <span class="key">function</span> connectFault(fault:Object):Void {
<span class="lineno" id="134">   134  </span>		_isConnected = <span class="key">false</span>;
<span class="lineno" id="135">   135  </span>		Dispatcher.$.dispatchEvent( <span class="key">new</span> SOAPEvent( SOAPEvent.FAULT, {fault:fault} ) );
<span class="lineno" id="136">   136  </span>		<span class="key">if</span> (_isVerbose) Logger.$.fatal( _instance.toString( ), <span class="str_const">"Webservice Connection FAILURE Fault: '"</span> + _wsdl + <span class="str_const">"'\nfaultstring: "</span> + fault.faultstring + <span class="str_const">"\nfaultcode: "</span> + fault.faultcode + <span class="str_const">"\ndetail: "</span> + fault.detail + <span class="str_const">"\nfaultactor: "</span> + fault.faultactor + <span class="str_const">"\nfault: "</span> + fault );		
<span class="lineno" id="137">   137  </span>	}
<span class="lineno" id="138">   138  </span>
<span class="lineno" id="139">   139  </span>	<span class="comment doc">/**
<span class="lineno" id="140">   140  </span>	 * Call onResult Handler
<span class="lineno" id="141">   141  </span>	 * @param method (String)
<span class="lineno" id="142">   142  </span>	 * @param result (Object)
<span class="lineno" id="143">   143  </span>	 * @return Void
<span class="lineno" id="144">   144  </span>	 */</span>
<span class="lineno" id="145">   145  </span>	<span class="key">private</span> <span class="key">function</span> callResult(method:String, result:Object):Void {
<span class="lineno" id="146">   146  </span>		Dispatcher.$.dispatchEvent( <span class="key">new</span> SOAPEvent( SOAPEvent.CALL_RESULT, {method:method, result:result} ) );	
<span class="lineno" id="147">   147  </span>		<span class="key">if</span> (_isVerbose) {
<span class="lineno" id="148">   148  </span>			Logger.$.info( _instance.toString( ), <span class="str_const">"Webservice Call Result: '"</span> + method + <span class="str_const">"'\nresult ("</span> + TypeValidation.getType( result ).name + <span class="str_const">"): "</span> + result );
<span class="lineno" id="149">   149  </span>		}
<span class="lineno" id="150">   150  </span>	}
<span class="lineno" id="151">   151  </span>
<span class="lineno" id="152">   152  </span>	<span class="comment doc">/**
<span class="lineno" id="153">   153  </span>	 * Call onFault Handler
<span class="lineno" id="154">   154  </span>	 * @param method (String)
<span class="lineno" id="155">   155  </span>	 * @param fault (Object)
<span class="lineno" id="156">   156  </span>	 * @return Void
<span class="lineno" id="157">   157  </span>	 */</span>
<span class="lineno" id="158">   158  </span>	<span class="key">private</span> <span class="key">function</span> callFault(method:String, response:Object, request:Object, fault:Object):Void {
<span class="lineno" id="159">   159  </span>		Dispatcher.$.dispatchEvent( <span class="key">new</span> SOAPEvent( SOAPEvent.CALL_FAULT, {method:method, fault:fault} ) );
<span class="lineno" id="160">   160  </span>		<span class="key">if</span> (_isVerbose) {
<span class="lineno" id="161">   161  </span>			<span class="key">var</span> props:String = <span class="str_const">""</span>, call:String = <span class="str_const">""</span>;
<span class="lineno" id="162">   162  </span>			<span class="key">for</span>(<span class="key">var</span> i:String <span class="key">in</span> SOAPCall) props += <span class="str_const">"\nSOAPCall Properties: "</span> + i + <span class="str_const">"  "</span> + <span class="key">this</span>[i];
<span class="lineno" id="163">   163  </span>			<span class="key">for</span> (<span class="key">var</span> j:String <span class="key">in</span> SOAPCall) call += <span class="str_const">"\nSOAPCall-&gt; "</span> + j + <span class="str_const">" "</span> + SOAPCall[j];
<span class="lineno" id="164">   164  </span>			Logger.$.error( _instance.toString( ), <span class="str_const">"Webservice Call Fault: '"</span> + method + <span class="str_const">"'\nfaultstring: "</span> + fault.faultstring + <span class="str_const">"\nfaultcode: "</span> + fault.faultcode + <span class="str_const">"\ndetail: "</span> + fault.detail + <span class="str_const">"\nfaultactor: "</span> + fault.faultactor + <span class="str_const">"\nrequest: "</span> + request + <span class="str_const">"\nSOAP response envelope: "</span> + response + <span class="str_const">"\nfault: "</span> + fault + <span class="str_const">"\n"</span> + props + <span class="str_const">"\n"</span> + call );
<span class="lineno" id="165">   165  </span>		}		
<span class="lineno" id="166">   166  </span>	}	
<span class="lineno" id="167">   167  </span>}</pre><ul class="main_nav" id="main_nav"><li><a href="../../../overview-summary.html" title="Overview of SASAPI" class="button">Overview</a></li><li><a href="package-summary.html" title="Overview of package com.sekati.services" class="button">Package</a></li><li><a href="SOAPClient.html" title="Detail of com.sekati.services.SOAPClient API" class="button">Class</a></li><li><span class="button nav_current">Source</span></li><li><a href="../../../index-files/index.html" title="Alpabetical index of types and members" class="button">Index</a></li></ul><div class="footer"><a href="http://www.badgers-in-foil.co.uk/projects/as2api/" title="ActionScript 2 API Documentation Generator">as2api</a></div></body></html>